<script>
import store from '@/store/index.js';
import socket from '@/config/socket';
// #ifdef H5
import { h5Login } from '@/config/html5Utils';
// #endif
// #ifdef APP-PLUS
import APPUpdate from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
// #endif
export default {
	onLaunch: function (e) {
		// #ifdef H5
		if (location.search.indexOf('code') != -1) {
			this.getOpenId()
		}
		// #endif
		//取出缓存数据
		store.commit('setCacheData');
		// #ifdef MP-WEIXIN
		if (store.state.userInfo.token) {
			socket.init();
		}
		// #endif
		// #ifdef H5
		if (store.state.userInfo.token) {
			socket.init();
		} else {
			h5Login('force', () => {
				socket.init();
			});
		}
		// #endif
		// #ifdef APP-PLUS
		if (store.state.userInfo.token) {
			socket.init();
		}
		//APPUpdate();
		// #endif
		// uni.hideTabBar()
	},
	onShow: function (e) {
		// #ifdef MP-WEIXIN
		//获取二维码携带的参数
		let scene = decodeURIComponent(e.query.scene);
		scene = scene.split('&');
		let data = {
			//场景值
			scene: e.scene
		};
		scene.forEach(item => {
			let arr = item.split('=');
			if (arr.length == 2) {
				data[arr[0]] = arr[1];
			}
		});
		store.commit('setChatScenesInfo', Object.assign(e.query, data));
		//小程序更新
		if (uni.getUpdateManager) {
			const updateManager = uni.getUpdateManager();
			updateManager.onCheckForUpdate(function (res) {
				// 请求完新版本信息的回调
				// console.log(res.hasUpdate);
			});
			updateManager.onUpdateReady(function (res) {
				uni.showModal({
					title: '更新提示',
					content: '新版本已经准备好，是否重启应用？',
					success (res) {
						if (res.confirm) {
							// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
							updateManager.applyUpdate();
						}
					}
				});
			});
			updateManager.onUpdateFailed(function (res) {
				// 新的版本下载失败
				uni.showModal({
					title: '已经有新版本了哟~',
					content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~',
					showCancel: false
				});
			});
		}
		// #endif
	},
	created () {



	},
	onHide: function () {},
	methods: {
		getUrlCode () { // 截取url中的code方法
			console.log('3333333333333333333333333333333333333333', '8788')
			var url = location.search
			if (location.search.indexOf('&divform=') != -1) {
				url = location.search.split('&divform=')[0]
			}

			var theRequest = new Object()
			if (url.indexOf("?") != -1) {
				var str = url.substr(1)
				var strs = str.split("&")
				for (var i = 0; i < strs.length; i++) {
					theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1])
				}
			}

			return location.search.indexOf('&divform=') != -1 ? {
				...theRequest,
				divform: decodeURIComponent(location.search.split('&divform=')[location.search.split('&divform=')
					.length - 1])
			} : theRequest
		},
		getOpenId () {
			if (location.search.indexOf('code') == -1) {

			} else {

				// uni.showToast({
				// 	title:'code:===='+this.getUrlCode().code+'---------app。this.getUrlCode().code',
				// 	icon:'none'
				// })
				this.$http.post('api/login/bandwx', {
					code: this.getUrlCode().code
				}).then(res => {
					// uni.showToast({
					// 	title:'获取get_openid'
					// })
					console.log(`uni.setStorageSync('openid',res.data.openid)`, "*********")
					console.log(res)
					uni.setStorageSync('openid', res.openid ? res.openid : uni.getStorageSync('openid'))
				});
			}
		}
	}

};
</script>

<style lang="scss">
/* 引入uview全局样式 */
@import "./tm-vuetify/mian.min.css";
@import "uview-ui/index.scss";
@import './style/font.css';
/* #ifndef APP-NVUE */
@import './style/common.scss';
@import './style/input.scss';
@import './style/table.scss';


page {
	font-family: PingFangSC-Regular, PingFang SC;
	height: 100%;

	background: #F6F8FA;
}

/* #endif */

/* #ifdef H5 */
//修复H5底部导航挡住内容bug
uni-app {
	height: auto;
}

//修复H5输入框上下不居中bug
.uni-input-form {
	height: 100%;
}

//去除地图上高德地图标识符
.amap-copyright {
	display: none !important;
}

.amap-logo {
	display: none !important;
}

.amap-ui-control-zoom {
	width: 60upx !important;
}

.amap-ui-control-zoom>* {
	width: 60upx !important;
	height: 60upx !important;
	line-height: 60upx !important;
}

.amap-ui-control-theme-dark {
	display: none !important;
}

/* #endif */
/deep/ .u-navbar__content__title {
	color: #fff;
}

.u-read-more__conten {
	text-indent: 0 !important;
}

/deep/ .uni-system-choose-location .list {
	margin-top: -100rpx;
	background-color: #fff;
	position: relative;
	top: 50px;
	left: 0;
	width: 100%;
	bottom: 0;
	padding-bottom: 10px;
}



.flex-row-flex-start {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: flex-start;
}

.flex-row-flex-start1 {
	display: flex;
	flex-direction: row;
	// align-items: center;
	justify-content: flex-start;
}

.flex-row-center {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: center;
}

.flex-column-center {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.flex-column-center1 {
	display: flex;
	flex-direction: column;
	// align-items: center;
	justify-content: center;
}

.flex-column-flex-start {
	display: flex;
	flex-direction: column;
	// align-items: center; 
	justify-content: flex-start;
}

.flex-column-flex-start1 {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
}

.flex-row-space-between {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
}

.flex-row-space-between1 {
	display: flex;
	flex-direction: row;
	// align-items: center;
	justify-content: space-between;
}

.flex-row-space-around {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-around;
}

.flex-column-space-between {
	display: flex;
	flex-direction: column;
	/* align-items: center; */
	justify-content: space-between;
}

.flex-row-flex-end {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: flex-end;
}

.flex-column-flex-end {
	display: flex;
	flex-direction: column;
	vertical-align: center;
	justify-content: flex-end;
}


.display-flex {
	display: flex;
}

.flex-direction-row {
	flex-direction: row;
}

.flex-direction-column {
	flex-direction: column;
}

.justify-content-flex-start {
	justify-content: flex-start;
}

.justify-content-center {
	justify-content: center;
}

.align-items-flex-start {
	align-items: flex-start;
}

.align-items-center {
	align-items: center;
}

.justify-content-space-between {
	justify-content: space-between;
}

.justify-content-flex-end {
	justify-content: flex-end;
}

.vertical-align-center {
	vertical-align: center;
}

.BGImage {
	position: fixed;
	width: 100%;
	height: 100%;
	top: 0;
	left: 0;
	z-index: -1;
}

.flex1 {
	flex: 1
}

.flex-wrap {
	flex-wrap: wrap;
}

/* 其他 */
.relative {
	position: relative;
}

.absolute {
	position: absolute;
}

.fixed {
	position: fixed;
}

.fixed-top {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 99;
}

.fixed-bottom {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	z-index: 99;
}

.bottomLine {
	height: 200rpx;
}

.leftButton {
	padding-top: 26rpx;
	margin-left: 26rpx;
	/* #ifdef MP||APP-PLUS */
	padding-top: $MPTop;
	/* #endif */
	z-index: 999;
}
</style>
<style lang="scss">
// @import "@/uni_modules/uview-ui/index.scss";
/*每个页面公共css */
// @import "./tm-vuetify/mian.min.css";
// @import "./tm-vuetify/scss/theme.css";

* {
	margin: 0;
	padding: 0;
}

.uni-tabbar {
	box-shadow: 0px -4px 10px rgba(0, 0, 0, 0.06);
}

.flex1 {
	flex: 1
}

.img {
	vertical-align: top;
}

page {
	width: 750rpx;
	// height: 100%;
	background: #F8F8F8;
}

.flex-row-flex-start {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: flex-start;
}

.flex-row-flex-start1 {
	display: flex;
	flex-direction: row;
	// align-items: center;
	justify-content: flex-start;
}

.flex-row-center {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: center;
}

.flex-column-center {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.flex-column-center1 {
	display: flex;
	flex-direction: column;
	// align-items: center;
	justify-content: center;
}

.flex-column-flex-start {
	display: flex;
	flex-direction: column;
	// align-items: center; 
	justify-content: flex-start;
}

.flex-column-flex-start1 {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
}

.flex-row-space-between {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
}

.flex-row-space-between1 {
	display: flex;
	flex-direction: row;
	// align-items: center;
	justify-content: space-between;
}

.flex-row-space-around {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-around;
}

.flex-column-space-between {
	display: flex;
	flex-direction: column;
	/* align-items: center; */
	justify-content: space-between;
}

.flex-row-flex-end {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: flex-end;
}

.flex-column-flex-end {
	display: flex;
	flex-direction: column;
	vertical-align: center;
	justify-content: flex-end;
}


.display-flex {
	display: flex;
}

.flex-direction-row {
	flex-direction: row;
}

.flex-direction-column {
	flex-direction: column;
}

.justify-content-flex-start {
	justify-content: flex-start;
}

.justify-content-center {
	justify-content: center;
}

.align-items-flex-start {
	align-items: flex-start;
}

.align-items-center {
	align-items: center;
}

.justify-content-space-between {
	justify-content: space-between;
}

.justify-content-flex-end {
	justify-content: flex-end;
}

.vertical-align-center {
	vertical-align: center;
}

.BGImage {
	position: fixed;
	width: 100%;
	height: 100%;
	top: 0;
	left: 0;
	z-index: -1;
}

.flex1 {
	flex: 1
}

.flex-wrap {
	flex-wrap: wrap;
}

/* 其他 */
.relative {
	position: relative;
}

.absolute {
	position: absolute;
}

.fixed {
	position: fixed;
}

.fixed-top {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 99;
}

.fixed-bottom {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	z-index: 99;
}
</style>